<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <link href="https://gmpg.org/xfn/11" rel="profile">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="Hugo 0.80.0" />

  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>KotLin - 包的定义与导入 &middot; K J</title>
  <meta name="description" content="" />

  
  <link type="text/css" rel="stylesheet" href="http://kartjim.gitee.io/hugo/css/print.css" media="print">
  <link type="text/css" rel="stylesheet" href="http://kartjim.gitee.io/hugo/css/poole.css">
  <link type="text/css" rel="stylesheet" href="http://kartjim.gitee.io/hugo/css/syntax.css">
  <link type="text/css" rel="stylesheet" href="http://kartjim.gitee.io/hugo/css/hyde.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Abril+Fatface|PT+Sans:400,400i,700">


  
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144-precomposed.png">
  <link rel="icon" href="/hugo/favicon.png">
  
  
</head>

  <body class="theme-base-09 ">
  <aside class="sidebar">
  <div class="container sidebar-sticky">
    <div class="sidebar-about">
      <a href="http://kartjim.gitee.io/hugo/"><h1>K J</h1></a>
      <p class="lead">
       kart jim`blog 
      </p>
    </div>

    <nav>
      <ul class="sidebar-nav">
        <li><a href="http://kartjim.gitee.io/hugo/">Home</a> </li>
        <li><a href="https://blog.csdn.net/qq_46590483?spm=1001.2100.3001.5343"> CSDN </a></li><li><a href="https://github.com/can-dy-jack"> Github </a></li><li><a href="https://www.cnblogs.com/kartjim"> 博客园 </a></li>
      </ul>
    </nav>

    <p>Copyright 2021 © kart jim</p>
  </div>
</aside>

    <main class="content container">
    <div class="post">
  <h1>KotLin - 包的定义与导入</h1>
  <time datetime=2020-12-11T12:00:00Z class="post-date">Fri, Dec 11, 2020</time>
  <h1 id="kotlin---包的定义与导入">KotLin - 包的定义与导入</h1>
<p>包的声明应处于源⽂件顶部：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-kotlin" data-lang="kotlin"><span style="color:#66d9ef">package</span> my.demo
<span style="color:#66d9ef">import</span> kotlin.text.*
<span style="color:#75715e">// …… 
</span></code></pre></div><p>⽬录与包的结构⽆需匹配：源代码可以在⽂件系统的任意位置。</p>
<h2 id="包">包</h2>
<p>源⽂件通常以包声明开头：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-kotlin" data-lang="kotlin"><span style="color:#66d9ef">package</span> org.example
<span style="color:#66d9ef">fun</span> <span style="color:#a6e22e">printMessage</span>() { <span style="color:#75715e">/*……*/</span> }
<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Message</span> { <span style="color:#75715e">/*……*/</span> }
<span style="color:#75715e">// ……
</span></code></pre></div><p>源⽂件所有内容（⽆论是类还是函数）都包含在声明的包内。 所以上例中 <code>printMessage()</code> 的全名是
<code>org.example.printMessage</code> ， ⽽ <code>Message</code> 的全名是 <code>org.example.Message</code> 。</p>
<p><a href="https://blog.csdn.net/moriafly/article/details/107279590">博客来自：</a>moriafly</p>

</div>


    </main>

    
      
    
  </body>
</html>
